package com.panshi.servers.impl;

import com.panshi.api.bean.AnswerCommentsHDBean;
import com.panshi.api.bean.AnswerCommentsLinkBean;
import com.panshi.api.util.PageSizeVO;
import com.panshi.mapper.AnswerCommentsHDMapper;
import com.panshi.pojo.AnswerCommentsHDVO;
import com.panshi.pojo.AnswerHDVO;
import com.panshi.servers.AnswerCommentsHDServers;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XiaoWangYa
 * @version 1.0
 * @date 2020/8/11 0011 下午 9:53
 */
@Slf4j
@Service
@Api("回答评论Servers层")
public class AnswerCommentsHDServersImpl implements AnswerCommentsHDServers {

    @Autowired
    private AnswerCommentsHDMapper answerCommentsHDMapper;

    @Override   // 回答评论新增
    @CacheEvict(value = "comments", allEntries = true)
    public int addAnswerCommentsHDInfo(AnswerCommentsHDBean answerCommentsHDBean) {
        return answerCommentsHDMapper.addAnswerCommentsHDInfo(answerCommentsHDBean);
    }

    @Override   // 回答评论删除
    @CacheEvict(value = "comments", allEntries = true)
    public void deleteUserAnswerComments(int id) {
        answerCommentsHDMapper.deleteUserAnswerComments(id);
    }

    @Override   // 查询指定回答下所有评论
    @Cacheable(value = "comments", key = "#root.methodName + #p0.aid")
    public List<AnswerCommentsHDVO> queryAssignAnswerCommentsAll(PageSizeVO pageSizeVO) {
        return answerCommentsHDMapper.queryAssignAnswerCommentsAll(pageSizeVO);
    }

    @Override   // 查询评论回复
    @Cacheable(value = "comments", key = "#root.methodName + #p0.depth")
    public List<AnswerCommentsHDVO> queryAssginAnswerReplyInfo(PageSizeVO pageSizeVO) {
        return answerCommentsHDMapper.queryAssginAnswerReplyInfo(pageSizeVO);
    }

    @Override   // 查询指定回答信息
    @Cacheable(value = "comments", key = "#root.methodName + #id")
    public AnswerHDVO queryAssignAnswer(int id) {
        return answerCommentsHDMapper.queryAssignAnswer(id);
    }

    @Override   // 增加指定回答评论量
    @CacheEvict(value = "comments", allEntries = true)
    public void updateAnswerCountSum(AnswerHDVO answerHDVO) {
        answerCommentsHDMapper.updateAnswerCountSum(answerHDVO);
    }

    @Override   // 查询指定评论信息
    @Cacheable(value = "comments", key = "#root.methodName + #id")
    public AnswerCommentsHDVO queryAssginComments(int id) {
        return answerCommentsHDMapper.queryAssginComments(id);
    }

    @Override   // 点赞评论
    @CacheEvict(value = "commentsLink", allEntries = true)
    public void updateAssignAnswerCommentsLink(AnswerCommentsHDVO answerCommentsHDVO) {
        answerCommentsHDMapper.updateAssignAnswerCommentsLink(answerCommentsHDVO);
    }

    @Override   // 取消评论点赞
    @CacheEvict(value = "commentsLink", allEntries = true)
    public void cancelAnswerCommentsLink(AnswerCommentsLinkBean answerCommentsLinkBean) {
        answerCommentsHDMapper.cancelAnswerCommentsLink(answerCommentsLinkBean);
    }

    @Override   // 增加评论点赞信息
    @CacheEvict(value = "comments", allEntries = true)
    public void addAnswerCommentsLinkfo(AnswerCommentsLinkBean answerCommentsLinkBean) {
        answerCommentsHDMapper.addAnswerCommentsLinkfo(answerCommentsLinkBean);
    }

    @Override   // 查询评论是否被指定用户所点赞
    @Cacheable(value = "commentsLink", key = "#root.methodName + #p0.rid")
    public AnswerCommentsLinkBean queryAnswerCommentsLink(AnswerCommentsLinkBean answerCommentsLinkBean) {
        return answerCommentsHDMapper.queryAnswerCommentsLink(answerCommentsLinkBean);
    }
}
